<?php

namespace app\admin\model\xuexin;

use think\Model;


class Weivideo extends Model
{

    

    

    // 表名
    protected $name = 'xuexin_weivideo';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'status_text',
        'is_home_text',
        'type_text',
        'is_goods_text'
    ];
    

    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }

    
    public function getStatusList()
    {
        return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
    }

    public function getIsHomeList()
    {
        return ['推荐' => __('推荐'), '不推荐' => __('不推荐')];
    }

    public function getTypeList()
    {
        return ['一等奖' => __('一等奖'), '二等奖' => __('二等奖'), '三等奖' => __('三等奖'), '无奖' => __('无奖')];
    }

    public function getIsGoodsList()
    {
        return ['否' => __('否'), '是' => __('是')];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsHomeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_home']) ? $data['is_home'] : '');
        $list = $this->getIsHomeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsGoodsTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_goods']) ? $data['is_goods'] : '');
        $list = $this->getIsGoodsList();
        return isset($list[$value]) ? $list[$value] : '';
    }




}
